home *** CD-ROM | disk | FTP | other *** search
- head 1.12;
- branch ;
- access ;
- symbols ;
- locks ; strict;
- comment @ * @;
-
-
- 1.12
- date 89.09.20.17.26.11; author rab; state Exp;
- branches ;
- next 1.11;
-
- 1.11
- date 89.02.27.17.50.18; author mgbaker; state Exp;
- branches ;
- next 1.10;
-
- 1.10
- date 89.01.11.14.56.04; author rab; state Exp;
- branches ;
- next 1.9;
-
- 1.9
- date 89.01.01.21.21.18; author rab; state Exp;
- branches ;
- next 1.8;
-
- 1.8
- date 88.08.12.17.41.16; author ouster; state Exp;
- branches ;
- next 1.7;
-
- 1.7
- date 88.07.29.18.59.13; author ouster; state Exp;
- branches ;
- next 1.6;
-
- 1.6
- date 88.07.29.18.55.09; author ouster; state Exp;
- branches ;
- next 1.5;
-
- 1.5
- date 88.07.25.14.23.53; author ouster; state Exp;
- branches ;
- next 1.4;
-
- 1.4
- date 88.07.25.13.13.54; author ouster; state Exp;
- branches ;
- next 1.3;
-
- 1.3
- date 88.07.25.11.25.21; author ouster; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 88.06.21.17.26.17; author ouster; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 88.06.19.14.32.08; author ouster; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
- 1.12
- log
- @Changed #ifdef's so that sun4's use stdarg.h.
- @
- text
- @/*
- * syslog.c --
- *
- * Sprite version of 4.3BSD's syslog facilty.
- *
- */
-
- /*
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved. The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
- */
-
- #if defined(LIBC_SCCS) && !defined(lint)
- static char sccsid[] = "@@(#)syslog.c 5.10 (Berkeley) 4/20/87";
- #endif LIBC_SCCS and not lint
-
- /*
- * SYSLOG -- print message on log file
- *
- * This routine looks a lot like printf, except that it
- * outputs to the log file instead of the standard output.
- * Also:
- * adds a timestamp,
- * prints the module name in front of the message,
- * has some other formatting types (or will sometime),
- * adds a newline on the end of the message.
- *
- * The output of this routine is intended to be read by /etc/syslogd.
- *
- * Author: Eric Allman
- * (Modified to use UNIX domain IPC by Ralph Campbell)
- * Modified to use the Sprite /dev/syslog, fall 1987
- */
-
- #include <sys/types.h>
- #include <sys/file.h>
- #include <signal.h>
- #include <sys/syslog.h>
- #include <netdb.h>
- #include <strings.h>
- #include <stdio.h>
- #include <sys/wait.h>
-
- #if defined(__STDC__) && !defined(spur) && !defined(sun4)
- #include <stdarg.h>
- #else
- #include <varargs.h>
- #endif
-
- #define MAXLINE 1024 /* max message size */
-
- #define PRIFAC(p) (((p) & LOG_FACMASK) >> 3)
- #define IMPORTANT LOG_ERR
-
- static char logname[] = "/dev/syslog";
- static char ctty[] = "/dev/console";
-
- static int LogFile = -1; /* fd for log */
- static int LogStat = 0; /* status bits, set by openlog() */
- static char *LogTag = "syslog"; /* string to tag the entry with */
- static int LogMask = 0xff; /* mask of priorities to be logged */
- static int LogFacility = LOG_USER; /* default facility code */
-
-
- extern int errno, sys_nerr;
- extern char *sys_errlist[];
- extern long time();
- extern char *ctime();
-
- extern int setlogmask();
- extern void closelog();
- extern void openlog();
-
- #ifndef lint
- #if defined(__STDC__) && !defined(spur) && !defined(sun4)
- void
- syslog(int pri, const char *fmt, ...)
- {
- #else
- void
- syslog(va_alist)
- va_dcl
- {
- int pri;
- char *fmt;
- #endif
- char buf[MAXLINE + 1], outline[MAXLINE + 1];
- register char *b, *o;
- #ifdef __STDC__
- register const char *f;
- #else
- register char *f;
- #endif
- register int c;
- long now;
- int pid, olderrno = errno;
- va_list args;
-
- #if defined(__STDC__) && !defined(spur) && !defined(sun4)
- va_start(args, fmt);
- #else
- va_start(args);
- pri = va_arg(args, int);
- fmt = va_arg(args, char *);
- #endif
- /* see if we should just throw out this message */
- if (pri <= 0 || PRIFAC(pri) >= LOG_NFACILITIES ||
- (LOG_MASK(pri) & LogMask) == 0)
- return;
- if (LogFile < 0)
- openlog(LogTag, LogStat | LOG_NDELAY, 0);
-
- /* set default facility if none specified */
- if ((pri & LOG_FACMASK) == 0)
- pri |= LogFacility;
-
- /* build the message */
- o = outline;
- sprintf(o, "<%d>", pri);
- o += strlen(o);
- time(&now);
- sprintf(o, "%.15s ", ctime(&now) + 4);
- o += strlen(o);
- if (LogTag) {
- strcpy(o, LogTag);
- o += strlen(o);
- }
- if (LogStat & LOG_PID) {
- sprintf(o, "[%x]", getpid());
- o += strlen(o);
- }
- if (LogTag) {
- strcpy(o, ": ");
- o += 2;
- }
-
- b = buf;
- f = fmt;
- while ((c = *f++) != '\0' && c != '\n' && b < &buf[MAXLINE]) {
- if (c != '%') {
- *b++ = c;
- continue;
- }
- if ((c = *f++) != 'm') {
- *b++ = '%';
- *b++ = c;
- continue;
- }
- if ((unsigned)olderrno > sys_nerr)
- sprintf(b, "error %d", olderrno);
- else
- strcpy(b, sys_errlist[olderrno]);
- b += strlen(b);
- }
- *b++ = '\n';
- *b = '\0';
- vsprintf(o, buf, args);
- va_end(args);
- c = strlen(outline);
- if (c > MAXLINE)
- c = MAXLINE;
-
- /* output the message to the local logger */
- if (write(LogFile, outline, c) >= 0)
- return;
- if (!(LogStat & LOG_CONS))
- return;
-
- /* output the message to the console */
- pid = vfork();
- if (pid == -1)
- return;
- if (pid == 0) {
- int fd;
-
- sigsetmask(sigblock(0));
- fd = open(ctty, O_WRONLY);
- strcat(o, "\r");
- o = index(outline, '>') + 1;
- write(fd, o, c + 1 - (o - outline));
- close(fd);
- _exit(0);
- }
- if (!(LogStat & LOG_NOWAIT))
- while ((c = wait((union wait *)0)) > 0 && c != pid)
- ;
- }
- #else /* lint */
- /*VARARGS2*/
- /*ARGSUSED*/
- void
- syslog(pri, fmt)
- int pri;
- char *fmt;
- {
- return;
- }
- #endif /* !lint */
-
- /*
- * OPENLOG -- open system log
- */
-
- void
- openlog(ident, logstat, logfac)
- char *ident;
- int logstat, logfac;
- {
- if (ident != NULL)
- LogTag = ident;
- LogStat = logstat;
- if (logfac != 0)
- LogFacility = logfac & LOG_FACMASK;
- if (LogFile >= 0)
- return;
-
- if (LogStat & LOG_NDELAY) {
- LogFile = open(logname, O_WRONLY, 0);
- fcntl(LogFile, F_SETFD, 1);
- }
- return;
- }
-
- /*
- * CLOSELOG -- close the system log
- */
-
- void
- closelog()
- {
-
- (void) close(LogFile);
- LogFile = -1;
- return;
- }
-
- /*
- * SETLOGMASK -- set the log mask level
- */
- int
- setlogmask(pmask)
- int pmask;
- {
- int omask;
-
- omask = LogMask;
- if (pmask != 0)
- LogMask = pmask;
- return (omask);
- }
- @
-
-
- 1.11
- log
- @Fixed things so sun4 cpp will work.
- @
- text
- @d71 4
- d90 1
- a90 1
- #if !defined (sun4)
- d205 1
- d222 1
- d229 1
- d235 1
- d241 1
- @
-
-
- 1.10
- log
- @Fixed syslog to take variable # of args.
- @
- text
- @d45 1
- a45 1
- #if defined(__STDC__) && !defined(spur)
- d72 1
- a72 1
- #if defined(__STDC__) && !defined(spur)
- d86 1
- d88 3
- d96 1
- a96 1
- #if defined(__STDC__) && !defined(spur)
- @
-
-
- 1.9
- log
- @Fixed syslog to take a variable number of arguments.
- @
- text
- @d45 1
- a45 1
- #ifdef __STDC__
- d72 1
- a72 1
- #ifdef __STDC__
- d75 1
- d78 5
- a82 4
- syslog(pri, fmt, va_alist)
- int pri;
- char *fmt;
- va_dcl
- a83 1
- {
- d92 7
- a149 5
- #ifdef __STDC__
- va_start(args, fmt);
- #else
- va_start(args);
- #endif
- @
-
-
- 1.8
- log
- @Reduce lint messages from syslog.
- @
- text
- @d45 6
- d71 11
- a81 4
- /* VARARGS2 */
- syslog(pri, fmt, p0, p1, p2, p3, p4)
- int pri;
- char *fmt;
- d84 2
- a85 1
- register char *b, *f, *o;
- d89 1
- d142 7
- a148 1
- sprintf(o, buf, p0, p1, p2, p3, p4);
- d178 11
- @
-
-
- 1.7
- log
- @Lint.
- @
- text
- @d65 1
- @
-
-
- 1.6
- log
- @Lint.
- @
- text
- @d43 1
- @
-
-
- 1.5
- log
- @Lint.
- @
- text
- @d152 1
- a152 1
- while ((c = wait((int *)0)) > 0 && c != pid)
- @
-
-
- 1.4
- log
- @Lint.
- @
- text
- @a44 1
- #define NULL 0 /* manifest */
- @
-
-
- 1.3
- log
- @Lint.
- @
- text
- @d42 1
- @
-
-
- 1.2
- log
- @Get headers from right place.
- @
- text
- @d61 2
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d38 1
- a38 1
- #include <sys/signal.h>
- @
-